<?php 
    $storeId = Mage::app()->getStore()->getId();
	$posts = Mage::getModel('blog/post')->getCollection()
			->setStoreId($storeId)	
			->addAttributeToSelect('*')
			->addAttributeToFilter('status',1)
			->addAttributeToSort('created_at','DESC');
    $thumnailWidth = Mage::getStoreConfig('blog/info/recent_thumbnail_width');
	$thumnailHeight = Mage::getStoreConfig('blog/info/recent_thumbnail_height');
    $helper = Mage::helper('cms');
	$helperBlog = Mage::helper('blog'); 
?>
<?php if($posts->count() > 0):?>
    <?php $_count = 1; foreach ($posts as $p): ?>
        <?php if($_count==1 || $_count%2==1):?>
        <div class="em-blog-grid-item em-blog-style04">
        <?php endif;?>
			<div class="em-blog-item em-wrapper-ads-12 ">
                <div class="em-blog-content col-sm-12 col-xs-10">
    				<?php if($p->getImage()):?>
    				<a title="em-sample-title" class="img-banner-small" href="<?php echo $p->getPostUrl();?>">
    					<img alt="em_blog" class="img-responsive" src="<?php echo $helperBlog->resizeImage($p->getImage(),$thumnailWidth,$thumnailHeight,"emblog/post",'thumbnail');?>"/>
    				</a>
    				<?php endif;?>
                    <?php $date = new DateTime($p->getCreatedAt());?>                    
                    <div class="em-blog-time">
                        <p class="em-blog-date"><?php echo $date->format('j'); ?></p>
                        <p class="em-blog-month"><?php echo $date->format('M'); ?></p>
                    </div>
                </div>
                
                <div class="col-sm-12 col-xs-14">
    				<?php
						$title = $p->getTitle();
						if (strlen($title) > 30)
						{
							$temp = substr($title, 0, 30);
							$plit = explode(" ", $temp);
							$temp = array_slice($plit, 0, count($plit) - 1);
							$title = implode(" ", $temp);
						}
					?>
					<h4 class="em-blog-title"><a href="<?php echo $p->getPostUrl(false);?>"><?php echo strip_tags($title);?>&hellip;</a></h4>
					<?php
						$content = $p->getPostIntro();
						if (strlen($content) > 150)
						{
							$temp = substr($content, 0, 150);
							$plit = explode(" ", $temp);
							$temp = array_slice($plit, 0, count($plit) - 1);
							$content = implode(" ", $temp);
						}
					?>
					<p class="em-blog-des"><?php echo strip_tags($content)?>&hellip;</p>
					<p><a class="link-more" href="<?php echo $p->getPostUrl();?>">Read more</a></p>
    			</div>
			</div>
        <?php if($_count%2==0 || $_count >= $posts->count() || $_count >= 6):?>
        </div>
        <?php endif;?>
        <?php if($_count >= 6) break;?>
        <?php $_count++;?>     
    <?php endforeach; ?>
<?php else:?>
    <p class="note-msg"><?php echo $this->__('There are no posts matching the selection.')?></p>
<?php endif;?>
